<?php

require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/wp-load.php';

if (isset($phonebook)) {
    //$q, $o, $l, $p, $s
    if (isset($_GET["f"]) && isset($_GET["q"]) && isset($_GET["o"]) && isset($_GET["l"]) && isset($_GET["p"]) && isset($_GET["s"]) ) {               
        // search data to export
        switch ($_GET['f']) {
            case "vcard": 
                $data = $phonebook->getSearchResultVCard($_GET['q'], $_GET['o'], $_GET['l'], $_GET['p'], $_GET['s']);
                if ($data) {
                    header('Content-type: text/x-vcard');
                    header('Content-Disposition: attachment; filename="contacts.vcf"');                    
                    print $data;
                    return;
                }
                break;
            
            default : 
                
                break;
        }
        wp_die(sprintf(__('Not found any contacts')));
    }
}
